package 代码随想录.数组;

import java.util.Scanner;

public class b44开发商购买土地 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] nums = new int[n][m];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                nums[i][j] = sc.nextInt();
                sum += nums[i][j];
            }
        }
        int res = Integer.MAX_VALUE;
        int count = 0;
        // 行切分
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                count += nums[i][j];
                if (j == m - 1) {
                    res = Math.min(res, Math.abs(sum - 2 * count));
                }
            }
        }
        count = 0;
        // 列切分
        for (int j = 0; j < m; j++) {
            for (int i = 0; i < n; i++) {
                count += nums[i][j];
                if (i == n - 1) {
                    res = Math.min(res, Math.abs(sum - 2 * count));
                }
            }
        }
        System.out.println(res);
    }
}
